001 /* EVolve - an Extensible Software Visualization Framework
002 * Copyright (C) 2001-2002 Qin Wang
003 *
004 * This library is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU Library General Public
006 * License as published by the Free Software Foundation; either
007 * version 2 of the License, or (at your option) any later version.
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Library General Public License for more details.
013 *
014 * You should have received a copy of the GNU Library General Public
015 * License along with this library; if not, write to the
016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017 * Boston, MA 02111-1307, USA.
018 */
019
020 /*
021 * EVolve is distributed at http://www.sable.mcgill.ca/evolve/
022 */
023
024 package EVolve;
025
026 import EVolve.data.*;
027 import EVolve.visualization.*;
028 import EVolve.visualization.VizFactory.*;
029 import java.util.*;
030
031 public class Main {
032 private static VisualizationFactory[] factory;
033 private static ArrayList dsList;
034
035 public static void main(String[] args) {
036 dsList = new ArrayList();
037 parseArgs(args);
038
039 /* This code has been moved to 'addVizLibrary' */
040 /*
041 VisualizationFactory[] factory = new VisualizationFactory[10];
042 factory[0] = new TableVizFactory();
043 factory[1] = new BarChartVizFactory();
044 factory[2] = new ThreadHotspotVizFactory();
045 factory[3] = new HotspotVizFactory();
046 factory[4] = new StackHotspotVizFactory();
047 factory[5] = new PredictionVizFactory();
048 factory[6] = new CorrelationVizFactory();
049 factory[7] = new StackVizFactory();
050 factory[8] = new DotPlotVizFactory();
051 factory[9] = new MissPredictionMetricVizFactory();
052 //factory[9] = new EscObjectVizFactory();
053 ((PredictionVizFactory)(factory[5])).addPredictorFactory(new DefaultPredictorFactory());
054 ((MissPredictionMetricVizFactory)(factory[9])).addPredictorFactory(new DefaultPredictorFactory());
055 */
056
057 //Scene.start(dataSource, factory);
058 Scene.start(dsList, factory);
059 }
060
061 public static void parseArgs(String[] args) {
062 factory = null;
063
064 HashMap vizFactories = new HashMap();
065
066 addVizLibrary(vizFactories);
067
068 try {
069 for (int i = 0; i < args.length; i++) {
070 if (args[i].equals("-d") || args[i].equals("--datasource")) {
071 StringTokenizer token = new StringTokenizer(args[++i],",");
072 while (token.hasMoreTokens()) {
073 String name = token.nextToken();
074 Object dsource = instanciateFromName(name);
075
076 if (dsource == null) {
077 System.err.println("EVolve> Failed to instanciate class: \"" + name + "\"");
078 System.exit(1);
079 } else if (dsource instanceof DataSource) {
080 dsList.add(dsource);
081 } else {
082 System.err.println("EVolve> \"" + args[i] + "\" is not a DataSource");
083 System.exit(2);
084 }
085 }
086 } else if (args[i].equals("+v") || args[i].equals("--addviz")) {
087 Object viz = instanciateFromName(args[++i]);
088 if (viz == null) {
089 System.err.println("EVolve> Failed to instanciate class: \"" + args[i] + "\"");
090 System.exit(1);
091 } else if (viz instanceof VisualizationFactory) {
092 vizFactories.put(args[i], viz);
093 } else {
094 System.err.println("EVolve> \"" + args[i] + "\" is not a VisualizationFactory");
095 System.exit(2);
096 }
097 } else if (args[i].equals("-v") || args[i].equals("--removeviz")) {
098 if (vizFactories.containsKey(args[++i])) {
099 vizFactories.remove(args[i]);
100 } else {
101 System.err.println("EVolve> Unknown visualization factory: \"" + args[i] + "\"");
102 System.exit(1);
103 }
104 } else if (args[i].equals("-h") || args[i].equals("--help")) {
105 System.out.println("Usage: java evolve.Main [options]");
106 System.out.println(" where options can be:");
107 System.out.println(" -h | --help");
108 System.out.println(" Prints this help message");
109 System.out.println(" -d | --datasource <data_source_1,data_source_2,...>");
110 System.out.println(" Specifies the class name of the data source to be used");
111 System.out.println(" +v | --addviz <viz factory>");
112 System.out.println(" Specifies the name of a visualization factory to be registered with EVolve");
113 System.out.println(" -v | --removeviz <viz factory>");
114 System.out.println(" Specifies the name of a visualization factory to be unregistered with EVolve");
115 System.out.println("");
116 System.out.println("Visit the EVolve page at http://www.sable.mcgill.ca/evolve");
117 System.exit(0);
118 } else {
119 System.err.println("EVolve> Unrecognized option: \"" + args[i] + "\"");
120 System.exit(1);
121 }
122 }
123 } catch (ArrayIndexOutOfBoundsException e) {
124 System.err.println("EVolve> Missing argument!!");
125 System.exit(3);
126 }
127
128 //if (dsList.size() == 0) {
129 dsList.add(0,new DemoSource()); // provide a default data source
130 //}
131
132 Collection factories = vizFactories.values();
133 factory = new VisualizationFactory[factories.size()];
134 int j = 0;
135 Iterator it = factories.iterator();
136 while (it.hasNext()) {
137 factory[j++] = (VisualizationFactory) it.next();
138 }
139 }
140
141 private static void addVizLibrary(HashMap vizFactories) {
142 vizFactories.put("TableVizFactory", new TableVizFactory());
143 vizFactories.put("BarChartVizFactory", new BarChartVizFactory());
144 vizFactories.put("ThreadHotspotVizFactory", new ThreadHotspotVizFactory());
145 vizFactories.put("HotspotVizFactory", new HotspotVizFactory());
146 vizFactories.put("StackHotspotVizFactory", new StackHotspotVizFactory());
147 PredictionVizFactory predViz = new PredictionVizFactory();
148 predViz.addPredictorFactory(new DefaultPredictorFactory());
149 vizFactories.put("PredictionVizFactory", predViz);
150 vizFactories.put("CorrelationVizFactory", new CorrelationVizFactory());
151 vizFactories.put("StackVizFactory", new StackVizFactory());
152 vizFactories.put("DotPlotVizFactory", new DotPlotVizFactory());
153 MissPredictionMetricVizFactory missPredViz = new MissPredictionMetricVizFactory();
154 missPredViz.addPredictorFactory(new DefaultPredictorFactory());
155 vizFactories.put("MissPredictionMetricVizFactory", missPredViz);
156 EventVizFactory eventViz = new EventVizFactory();
157 eventViz.addPredictorFactory(new DefaultPredictorFactory());
158 vizFactories.put("EventVizFactory", eventViz);
159 vizFactories.put("RelationshipVizFactory", new RelationshipVizFactory());
160 vizFactories.put("MetricVizFactory", new MetricVizFactory());
161 }
162
163 public static Object instanciateFromName(String className) {
164 /* Get a Class object corresponding to the given
165 class name using Java's Reflection API */
166 try {
167 Class klass = null;
168 try {
169 klass = Class.forName(className);
170 } catch (ClassNotFoundException e) {
171 System.err.println("EVolve> Class not found: \"" + className + "\"");
172 return null;
173 }
174
175 return klass.newInstance();
176 } catch (InstantiationException e) {
177 } catch (IllegalAccessException e) {
178 }
179
180 return null;
181 }
182 }
183